﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CognisessDA;
using CognisessCommLib;
using System.Data.SqlClient;
using System.Configuration;

namespace CognisessService
{
    public class AccountBLL
    {

        #region Public Method

        #region User
        public bool AddUser(List<User> users)
        {
            try
            {
                foreach (var item in users)
                {
                    item.CreateTime = DateTime.Now;
                }
                CognisessDataContext db = new CognisessDataContext();
                db.Users.InsertAllOnSubmit(users);
                db.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                return false;
            }
        }

        /// <summary>
        /// Query user 
        /// </summary>
        /// <param name="userCondition">except datatime field</param>
        /// <returns>users</returns>
        public List<User> GetUser(User userCondition)
        {
            CognisessDataContext db = new CognisessDataContext();
            var result = from o in db.Users
                         where o.Id == (userCondition.Id == 0 ? o.Id : userCondition.Id) &&
                               (o.AboutMe ?? string.Empty) == (string.IsNullOrEmpty(userCondition.AboutMe) ? (o.AboutMe ?? string.Empty) : userCondition.AboutMe) &&
                               (o.Address ?? string.Empty) == (string.IsNullOrEmpty(userCondition.Address) ? (o.Address ?? string.Empty) : userCondition.Address) &&
                               (o.Avater ?? string.Empty) == (string.IsNullOrEmpty(userCondition.Avater) ? (o.Avater ?? string.Empty) : userCondition.Avater) &&
                               o.EducationLevel == (userCondition.EducationLevel == 0 ? o.EducationLevel : userCondition.EducationLevel) &&
                               (o.Email ?? string.Empty) == (string.IsNullOrEmpty(userCondition.Email) ? (o.Email ?? string.Empty) : userCondition.Email) &&
                               (o.Fax ?? string.Empty) == (string.IsNullOrEmpty(userCondition.Fax) ? (o.Fax ?? string.Empty) : userCondition.Fax) &&
                               (o.Firstname ?? string.Empty) == (string.IsNullOrEmpty(userCondition.Firstname) ? (o.Firstname ?? string.Empty) : userCondition.Firstname) &&
                               (o.Industry ?? string.Empty) == (string.IsNullOrEmpty(userCondition.Industry) ? (o.Industry ?? string.Empty) : userCondition.Industry) &&
                               (o.Lastname ?? string.Empty) == (string.IsNullOrEmpty(userCondition.Lastname) ? (o.Lastname ?? string.Empty) : userCondition.Lastname) &&
                               (o.Occupation ?? string.Empty) == (string.IsNullOrEmpty(userCondition.Occupation) ? (o.Occupation ?? string.Empty) : userCondition.Occupation) &&
                               (o.Password ?? string.Empty) == (string.IsNullOrEmpty(userCondition.Password) ? (o.Password ?? string.Empty) : userCondition.Password) &&
                               (o.Telephone ?? string.Empty) == (string.IsNullOrEmpty(userCondition.Telephone) ? (o.Telephone ?? string.Empty) : userCondition.Telephone) &&
                               o.TimeZone == (userCondition.TimeZone == 0 ? o.TimeZone : userCondition.TimeZone) &&
                               (o.Username ?? string.Empty) == (string.IsNullOrEmpty(userCondition.Username) ? (o.Username ?? string.Empty) : userCondition.Username) &&
                               (o.Gender ?? 0) == ((userCondition.Gender == null || userCondition.Gender == 0) ? (o.Gender ?? 0) : userCondition.Gender) &&
                               o.HowToKnowUs == (userCondition.HowToKnowUs == 0 ? o.HowToKnowUs : userCondition.HowToKnowUs) &&
                               (o.IsActivated ?? 0) == ((userCondition.IsActivated == null || userCondition.IsActivated == 0) ? (o.IsActivated ?? 0) : userCondition.IsActivated) &&
                               (o.IsMarried ?? 0) == ((userCondition.IsMarried == null || userCondition.IsMarried == 0) ? (o.IsMarried ?? 0) : userCondition.IsMarried) &&
                               (o.IsTrial ?? 0) == ((userCondition.IsTrial == null || userCondition.IsTrial == 0) ? (o.IsTrial ?? 0) : userCondition.IsTrial) &&
                               (o.LoginNum ?? 0) == ((userCondition.LoginNum == null || userCondition.LoginNum == 0) ? (o.LoginNum ?? 0) : userCondition.LoginNum) &&
                               (o.OrgId ?? 0) == ((userCondition.OrgId == null || userCondition.OrgId == 0) ? (o.OrgId ?? 0) : userCondition.OrgId) &&
                               (o.RemainingDay ?? 0) == ((userCondition.RemainingDay == null || userCondition.RemainingDay == 0) ? (o.RemainingDay ?? 0) : userCondition.RemainingDay)

                         select o;

            return result.ToList();
        }

        public IQueryable<User> GetPagingUser(User userCondition)
        {
            CognisessDataContext db = new CognisessDataContext();
            var result = from o in db.Users
                         where o.Id == (userCondition.Id == 0 ? o.Id : userCondition.Id) &&
                               (o.AboutMe ?? string.Empty) == (string.IsNullOrEmpty(userCondition.AboutMe) ? (o.AboutMe ?? string.Empty) : userCondition.AboutMe) &&
                               (o.Address ?? string.Empty) == (string.IsNullOrEmpty(userCondition.Address) ? (o.Address ?? string.Empty) : userCondition.Address) &&
                               (o.Avater ?? string.Empty) == (string.IsNullOrEmpty(userCondition.Avater) ? (o.Avater ?? string.Empty) : userCondition.Avater) &&
                               o.EducationLevel == (userCondition.EducationLevel == 0 ? o.EducationLevel : userCondition.EducationLevel) &&
                               (o.Email ?? string.Empty) == (string.IsNullOrEmpty(userCondition.Email) ? (o.Email ?? string.Empty) : userCondition.Email) &&
                               (o.Fax ?? string.Empty) == (string.IsNullOrEmpty(userCondition.Fax) ? (o.Fax ?? string.Empty) : userCondition.Fax) &&
                               (o.Firstname ?? string.Empty) == (string.IsNullOrEmpty(userCondition.Firstname) ? (o.Firstname ?? string.Empty) : userCondition.Firstname) &&
                               (o.Industry ?? string.Empty) == (string.IsNullOrEmpty(userCondition.Industry) ? (o.Industry ?? string.Empty) : userCondition.Industry) &&
                               (o.Lastname ?? string.Empty) == (string.IsNullOrEmpty(userCondition.Lastname) ? (o.Lastname ?? string.Empty) : userCondition.Lastname) &&
                               (o.Occupation ?? string.Empty) == (string.IsNullOrEmpty(userCondition.Occupation) ? (o.Occupation ?? string.Empty) : userCondition.Occupation) &&
                               (o.Password ?? string.Empty) == (string.IsNullOrEmpty(userCondition.Password) ? (o.Password ?? string.Empty) : userCondition.Password) &&
                               (o.Telephone ?? string.Empty) == (string.IsNullOrEmpty(userCondition.Telephone) ? (o.Telephone ?? string.Empty) : userCondition.Telephone) &&
                               o.TimeZone == (userCondition.TimeZone == 0 ? o.TimeZone : userCondition.TimeZone) &&
                               (o.Username ?? string.Empty) == (string.IsNullOrEmpty(userCondition.Username) ? (o.Username ?? string.Empty) : userCondition.Username) &&
                               (o.Gender ?? 0) == ((userCondition.Gender == null || userCondition.Gender == 0) ? (o.Gender ?? 0) : userCondition.Gender) &&
                               o.HowToKnowUs == (userCondition.HowToKnowUs == 0 ? o.HowToKnowUs : userCondition.HowToKnowUs) &&
                               (o.IsActivated ?? 0) == ((userCondition.IsActivated == null || userCondition.IsActivated == 0) ? (o.IsActivated ?? 0) : userCondition.IsActivated) &&
                               (o.IsMarried ?? 0) == ((userCondition.IsMarried == null || userCondition.IsMarried == 0) ? (o.IsMarried ?? 0) : userCondition.IsMarried) &&
                               (o.IsTrial ?? 0) == ((userCondition.IsTrial == null || userCondition.IsTrial == 0) ? (o.IsTrial ?? 0) : userCondition.IsTrial) &&
                               (o.LoginNum ?? 0) == ((userCondition.LoginNum == null || userCondition.LoginNum == 0) ? (o.LoginNum ?? 0) : userCondition.LoginNum) &&
                               (o.OrgId ?? 0) == ((userCondition.OrgId == null || userCondition.OrgId == 0) ? (o.OrgId ?? 0) : userCondition.OrgId) &&
                               (o.RemainingDay ?? 0) == ((userCondition.RemainingDay == null || userCondition.RemainingDay == 0) ? (o.RemainingDay ?? 0) : userCondition.RemainingDay)

                         select o;

            return result;
        }

        public bool UpdataUser(List<User> users)
        {
            try
            {
                CognisessDataContext db = new CognisessDataContext();
                foreach (User item in users)
                {
                    User oldUser = db.Users.Where(p => p.Id == item.Id).FirstOrDefault();
                    // update user
                    oldUser.AboutMe = item.AboutMe;
                    oldUser.Address = item.Address;
                    oldUser.Avater = item.Avater;
                    oldUser.EducationLevel = item.EducationLevel;
                    oldUser.Email = item.Email;
                    oldUser.Fax = item.Fax;
                    oldUser.Firstname = item.Firstname;
                    oldUser.Industry = item.Industry;
                    oldUser.Lastname = item.Lastname;
                    oldUser.Occupation = item.Occupation;
                    oldUser.Password = item.Password;
                    oldUser.Telephone = item.Telephone;
                    oldUser.TimeZone = item.TimeZone;
                    oldUser.Username = item.Username;
                    oldUser.Gender = item.Gender;
                    oldUser.HowToKnowUs = item.HowToKnowUs;
                    oldUser.IsActivated = item.IsActivated;
                    oldUser.IsMarried = item.IsMarried;
                    oldUser.IsTrial = item.IsTrial;
                    oldUser.LoginNum = item.LoginNum;
                    oldUser.OrgId = item.OrgId;
                    oldUser.RemainingDay = item.RemainingDay;
                    oldUser.BirthDate = item.BirthDate;
                    oldUser.CreateTime = item.CreateTime;
                }
                db.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                return false;
            }
        }

        public bool DeleteUser(List<User> users)
        {
            try
            {
                CognisessDataContext db = new CognisessDataContext();
                db.Users.AttachAll(users, false);
                db.Users.DeleteAllOnSubmit(users);
                db.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                return false;
            }
        }

        public bool DeleteUser(int id)
        {
            try
            {
                CognisessDataContext db = new CognisessDataContext();
                User user = db.Users.Where(p => p.Id == id).FirstOrDefault();
                db.Users.DeleteOnSubmit(user);
                db.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                return false;
            }
        }
        #endregion

        #region FeedBack
        public bool AddFeedBack(List<Feedback> feedback)
        {
            try
            {
                CognisessDataContext db = new CognisessDataContext();
                db.Feedbacks.InsertAllOnSubmit(feedback);
                db.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                return false;
            }
        }

        public IQueryable<Feedback> GetPagingFeedback(Feedback condition)
        {
            CognisessDataContext db = new CognisessDataContext();
            var result = from o in db.Feedbacks
                         where o.Id == (condition.Id == 0 ? o.Id : condition.Id) &&
                         (o.Country ?? string.Empty) == (string.IsNullOrEmpty(condition.Country) ? (o.Country ?? string.Empty) : condition.Country) &&
                         (o.Email ?? string.Empty) == (string.IsNullOrEmpty(condition.Email) ? (o.Email ?? string.Empty) : condition.Email) &&
                         (o.FeedSubject ?? string.Empty) == (string.IsNullOrEmpty(condition.FeedSubject) ? (o.FeedSubject ?? string.Empty) : condition.FeedSubject)
                         select o;
            return result;
        }

        public List<Feedback> GetFeedback(Feedback condition)
        {
            CognisessDataContext db = new CognisessDataContext();
            var result = from o in db.Feedbacks
                         where o.Id == (condition.Id == 0 ? o.Id : condition.Id) &&
                         (o.Country ?? string.Empty) == (string.IsNullOrEmpty(condition.Country) ? (o.Country ?? string.Empty) : condition.Country) &&
                         (o.Email ?? string.Empty) == (string.IsNullOrEmpty(condition.Email) ? (o.Email ?? string.Empty) : condition.Email) &&
                         (o.FeedSubject ?? string.Empty) == (string.IsNullOrEmpty(condition.FeedSubject) ? (o.FeedSubject ?? string.Empty) : condition.FeedSubject)
                         select o;
            return result.ToList();
        }

        public bool UpdataFeedBack(List<Feedback> feedback)
        {
            try
            {
                CognisessDataContext db = new CognisessDataContext();
                foreach (Feedback item in feedback)
                {
                    Feedback old = db.Feedbacks.Where(p => p.Id == item.Id).FirstOrDefault();
                    // update FeedBack
                    old.Realname = item.Realname;
                    old.FeedSubject = item.FeedSubject;
                    old.FeedContent = item.FeedContent;
                    old.Email = item.Email;
                    old.CreateTime = item.CreateTime;
                    old.Country = item.Country;
                }
                db.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                return false;
            }
        }

        public bool DeleteFeedBack(int id)
        {
            try
            {
                CognisessDataContext db = new CognisessDataContext();
                Feedback feedbacks = db.Feedbacks.Where(p => p.Id == id).FirstOrDefault();
                db.Feedbacks.DeleteOnSubmit(feedbacks);
                db.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                return false;
            }
        }
        #endregion

        #region Career
        public bool AddCareer(List<Career> career)
        {
            try
            {
                CognisessDataContext db = new CognisessDataContext();
                db.Careers.InsertAllOnSubmit(career);
                db.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                return false;
            }
        }

        #endregion

        #region Blog

        public List<Blog> GetBlog(Blog blogCondition)
        {
            CognisessDataContext db = new CognisessDataContext();
            var result = from o in db.Blog
                         where o.Id == (blogCondition.Id == 0 ? o.Id : blogCondition.Id) &&
                         (o.Title ?? string.Empty) == (string.IsNullOrEmpty(blogCondition.Title) ? (o.Title ?? string.Empty) : blogCondition.Title) &&
                         (o.BloggerName ?? string.Empty) == (string.IsNullOrEmpty(blogCondition.BloggerName) ? (o.BloggerName ?? string.Empty) : blogCondition.BloggerName)
                         select o;
            return result.ToList();
        }

        public bool AddBlog(List<Blog> blogs)
        {
            try
            {
                CognisessDataContext db = new CognisessDataContext();
                db.Blog.InsertAllOnSubmit(blogs);
                db.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                return false;
            }
        }

        public bool UpdataBlog(List<Blog> blogs)
        {
            try
            {
                CognisessDataContext db = new CognisessDataContext();
                foreach (Blog item in blogs)
                {
                    Blog old = db.Blog.Where(p => p.Id == item.Id).FirstOrDefault();
                    // update blog
                    old.BloggerName = item.BloggerName;
                    old.Title = item.Title;
                    old.BlogContent = item.BlogContent;
                }
                db.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                return false;
            }
        }

        public bool DeleteBlog(int id)
        {
            try
            {
                CognisessDataContext db = new CognisessDataContext();
                Blog user = db.Blog.Where(p => p.Id == id).FirstOrDefault();
                db.Blog.DeleteOnSubmit(user);
                db.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                return false;
            }
        }
        
        #endregion

        #region Post
        public List<Post> GetPost(Post postCondition)
        {
            CognisessDataContext db = new CognisessDataContext();
            var result = from o in db.Posts
                         where o.Id == (postCondition.Id == 0 ? o.Id : postCondition.Id) &&
                         (o.Title ?? string.Empty) == (string.IsNullOrEmpty(postCondition.Title) ? (o.Title ?? string.Empty) : postCondition.Title) &&
                         (o.PostContent ?? string.Empty) == (string.IsNullOrEmpty(postCondition.PostContent) ? (o.PostContent ?? string.Empty) : postCondition.PostContent) &&
                         o.BlogId == (postCondition.BlogId == 0 ? o.BlogId : postCondition.BlogId) &&
                         o.NewsId == (postCondition.NewsId == 0 ? o.NewsId : postCondition.NewsId) &&
                         (o.dateCreated ?? null) == ((postCondition.dateCreated == null || postCondition.dateCreated == null) ? (o.dateCreated ?? null) : postCondition.dateCreated)
                         select o;
            return result.ToList();
        }

        public bool AddPost(List<Post> list)
        {
            try
            {
                CognisessDataContext db = new CognisessDataContext();
                db.Posts.InsertAllOnSubmit(list);
                db.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                return false;
            }
        }

        public bool UpdataPost(List<Post> list)
        {
            try
            {
                CognisessDataContext db = new CognisessDataContext();
                foreach (Post item in list)
                {
                    Post old = db.Posts.Where(p => p.Id == item.Id).FirstOrDefault();
                    // update post
                    old.PostContent = item.PostContent;
                    old.Title = item.Title;
                }
                db.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                return false;
            }
        }

        public bool DeletePost(int id)
        {
            try
            {
                CognisessDataContext db = new CognisessDataContext();
                Post posts = db.Posts.Where(p => p.Id == id).FirstOrDefault();
                db.Posts.DeleteOnSubmit(posts);
                db.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                return false;
            }
        }

        #endregion

        #region Comments
        public List<Comment> GetComment(Comment commentCondition)
        {
            CognisessDataContext db = new CognisessDataContext();
            var result = from o in db.Comments
                         where o.Id == (commentCondition.Id == 0 ? o.Id : commentCondition.Id) &&
                         (o.CommentContent ?? string.Empty) == (string.IsNullOrEmpty(commentCondition.CommentContent) ? (o.CommentContent ?? string.Empty) : commentCondition.CommentContent) &&
                         (o.DateCreated ?? null) == ((commentCondition.DateCreated == null || commentCondition.DateCreated == null) ? (o.DateCreated ?? null) : commentCondition.DateCreated)
                         select o;
            return result.ToList();
        }

        public bool AddComment(List<Comment> list)
        {
            try
            {
                CognisessDataContext db = new CognisessDataContext();
                db.Comments.InsertAllOnSubmit(list);
                db.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                return false;
            }
        }

        public bool UpdataComment(List<Comment> list)
        {
            try
            {
                CognisessDataContext db = new CognisessDataContext();
                foreach (Comment item in list)
                {
                    Comment old = db.Comments.Where(p => p.Id == item.Id).FirstOrDefault();
                    // update comment
                    old.CommentContent = item.CommentContent;
                }
                db.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                return false;
            }
        }

        public bool DeleteComment(int id)
        {
            try
            {
                CognisessDataContext db = new CognisessDataContext();
                Comment comments = db.Comments.Where(p => p.Id == id).FirstOrDefault();
                db.Comments.DeleteOnSubmit(comments);
                db.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                return false;
            }
        }

        #endregion

        #region NewsInfo

        public List<NewsInfo> GetNews(NewsInfo newCondition)
        {
            CognisessDataContext db = new CognisessDataContext();
            var result = from o in db.NewsInfo
                         where o.Id == (newCondition.Id == 0 ? o.Id : newCondition.Id) &&
                         (o.NewsName ?? string.Empty) == (string.IsNullOrEmpty(newCondition.NewsName) ? (o.NewsName ?? string.Empty) : newCondition.NewsName) &&
                         (o.Title ?? string.Empty) == (string.IsNullOrEmpty(newCondition.Title) ? (o.Title ?? string.Empty) : newCondition.Title)
                         select o;
            return result.ToList();
        }

        public bool AddNews(List<NewsInfo> list)
        {
            try
            {
                CognisessDataContext db = new CognisessDataContext();
                db.NewsInfo.InsertAllOnSubmit(list);
                db.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                return false;
            }
        }

        public bool UpdataNews(List<NewsInfo> list)
        {
            try
            {
                CognisessDataContext db = new CognisessDataContext();
                foreach (NewsInfo item in list)
                {
                    NewsInfo old = db.NewsInfo.Where(p => p.Id == item.Id).FirstOrDefault();
                    // update comment
                    old.NewsName = item.NewsName;
                    old.Title = item.Title;
                    old.NewsContent = item.NewsContent;
                }
                db.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                return false;
            }
        }

        public bool DeleteNews(int id)
        {
            try
            {
                CognisessDataContext db = new CognisessDataContext();
                NewsInfo newsInfos = db.NewsInfo.Where(p => p.Id == id).FirstOrDefault();
                db.NewsInfo.DeleteOnSubmit(newsInfos);
                db.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                return false;
            }
        }

        #endregion

        #region CareerPosition
        public List<CareerPosition> GetCareerPosition(CareerPosition condition)
        {
            CognisessDataContext db = new CognisessDataContext();
            var result = from o in db.CareerPositions
                         where o.Id == (condition.Id == 0 ? o.Id : condition.Id) &&
                         (o.Name ?? string.Empty) == (string.IsNullOrEmpty(condition.Name) ? (o.Name ?? string.Empty) : condition.Name) &&
                         o.PeopleNeed == (condition.PeopleNeed == 0 ? o.PeopleNeed : condition.PeopleNeed)
                         select o;
            return result.ToList();
        }

        public IQueryable<CareerPosition> GetPagingCareerPosition(CareerPosition condition)
        {
            CognisessDataContext db = new CognisessDataContext();
            var result = from o in db.CareerPositions
                         where o.Id == (condition.Id == 0 ? o.Id : condition.Id) &&
                         (o.Name ?? string.Empty) == (string.IsNullOrEmpty(condition.Name) ? (o.Name ?? string.Empty) : condition.Name) &&
                         o.PeopleNeed == (condition.PeopleNeed == 0 ? o.PeopleNeed : condition.PeopleNeed)
                         select o;
            return result;
        }

        public bool DeleteCareerPosition(int id)
        {
            try
            {
                CognisessDataContext db = new CognisessDataContext();
                CareerPosition user = db.CareerPositions.Where(p => p.Id == id).FirstOrDefault();
                db.CareerPositions.DeleteOnSubmit(user);
                db.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                return false;
            }
        }

        public bool AddCareerPosition(List<CareerPosition> careerPositions)
        {
            try
            {
                CognisessDataContext db = new CognisessDataContext();
                db.CareerPositions.InsertAllOnSubmit(careerPositions);
                db.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                return false;
            }
        }

        public bool UpdataCareerPosition(List<CareerPosition> careerPositions)
        {
            try
            {
                CognisessDataContext db = new CognisessDataContext();
                foreach (CareerPosition item in careerPositions)
                {
                    CareerPosition old = db.CareerPositions.Where(p => p.Id == item.Id).FirstOrDefault();
                    // update user
                    old.Name = item.Name;
                    old.IsVaild = item.IsVaild;
                    old.PeopleNeed = item.PeopleNeed;
                    old.Description = item.Description;
      
                }
                db.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                return false;
            }
        }

        #endregion

        #region ContentInfo
        public List<ContentInfo> GetContentInfo(ContentInfo contentInfo)
        {
            CognisessDataContext db = new CognisessDataContext();
            var result = from o in db.ContentInfo
                         where o.Id == (contentInfo.Id == 0 ? o.Id : contentInfo.Id) &&
                         (o.NavigationId == (contentInfo.NavigationId == 0 ? o.NavigationId : contentInfo.NavigationId)) &&
                         (o.MenuContent ?? string.Empty) == (string.IsNullOrEmpty(contentInfo.MenuContent) ? (o.MenuContent ?? string.Empty) : contentInfo.MenuContent) &&
                         (o.DateTime ?? null) == (contentInfo.DateTime == null ? (o.DateTime ?? null) : contentInfo.DateTime)
                         select o;
            return result.ToList();
        }

        public bool AddContentInfo(List<ContentInfo> collection)
        {
            try
            {
                CognisessDataContext db = new CognisessDataContext();
                db.ContentInfo.InsertAllOnSubmit(collection);
                db.SubmitChanges();
                return true;                
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                return false;
            }
        }

        public bool UpdataContentInfo(List<ContentInfo> contentInfo)
        {
            try
            {
                CognisessDataContext db = new CognisessDataContext();
                foreach (ContentInfo item in contentInfo)
            {
                ContentInfo old = db.ContentInfo.Where(p => p.Id == item.Id).FirstOrDefault();
                old.NavigationId = item.NavigationId;
                old.MenuContent = item.MenuContent;
                old.DateTime = item.DateTime;
            }
            db.SubmitChanges();
            return true;           
            }
            catch (Exception ex)
            {

                LogHelper.Error(ex.Message);
                return false;
            }
            
        }

        public bool DeleteContentInfo(int id)
        {
            try
            {
                CognisessDataContext db = new CognisessDataContext();
                ContentInfo menu = db.ContentInfo.Where(p => p.Id == id).FirstOrDefault();
                db.ContentInfo.DeleteOnSubmit(menu);
                db.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                return false;
            }
        }
        #endregion

        #region Navigation
        public List<Navigation> GetNavigation(Navigation navigation)
        {
            CognisessDataContext db = new CognisessDataContext();
            var result = from o in db.Navigation
                         where o.Id == (navigation.Id == 0 ? o.Id : navigation.Id) &&                        
                         (o.TitleName ?? string.Empty) == (string.IsNullOrEmpty(navigation.TitleName) ? (o.TitleName ?? string.Empty) : navigation.TitleName) 
                         select o;
            return result.ToList();
        }

        public bool AddNavigation(List<Navigation> collection)
        {
            try
            {
                CognisessDataContext db = new CognisessDataContext();
                db.Navigation.InsertAllOnSubmit(collection);
                db.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                return false;
            }
        }

        public bool DeleteNavigation(int id)
        {
            try
            {
                CognisessDataContext db = new CognisessDataContext();
                Navigation navigation = db.Navigation.Where(p => p.Id == id).FirstOrDefault();
                db.Navigation.DeleteOnSubmit(navigation);
                db.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                return false;
            }
        }

        public bool UpdataNavigation(List<Navigation> navigations)
        {
            try
            {
                CognisessDataContext db = new CognisessDataContext();
                foreach (Navigation item in navigations)
                {
                    Navigation old = db.Navigation.Where(p => p.Id == item.Id).FirstOrDefault();
                    old.TitleName = item.TitleName;
                    old.Link = item.Link;
                    old.ParentId = item.ParentId;
                    old.Sort = item.Sort;
                    old.Type = item.Type;
                }
                db.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {

                LogHelper.Error(ex.Message);
                return false;
            }
        }
        #endregion

        #region TestPage
        public bool AddTestRecord(List<TestRecord> list)
        {
            try
            {
                CognisessDataContext db = new CognisessDataContext();
                db.TestRecord.InsertAllOnSubmit(list);
                db.SubmitChanges();
                return true;
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex.Message);
                return false;
            }
        }

        public List<TestRecord> GetTestRecord(TestRecord testRecord)
        {
            CognisessDataContext db = new CognisessDataContext();
            var result = from o in db.TestRecord
                         where o.Id == (testRecord.Id == 0 ? o.Id : testRecord.Id) &&
                         (o.TestId == (testRecord.TestId == 0 ? o.TestId : testRecord.TestId)) &&
                         (o.UserId == (testRecord.UserId == 0 ? o.UserId : testRecord.UserId)) &&
                         (o.ResponseTime == (testRecord.ResponseTime == 0 ? o.ResponseTime : testRecord.ResponseTime)) &&
                         (o.StepNo == (testRecord.StepNo == 0 ? o.StepNo : testRecord.StepNo)) &&
                         (o.TotalTime == (testRecord.TotalTime == 0 ? o.TotalTime : testRecord.TotalTime)) &&
                         (o.Value ?? string.Empty) == (string.IsNullOrEmpty(testRecord.Value) ? (o.Value ?? string.Empty) : testRecord.Value) 
                         select o;
            return result.ToList();
        }
        #endregion
        #endregion

        #region Private Method

        #endregion























        
    }
}
